package lnp;

import static org.junit.Assert.assertTrue;
import lnp.test.RobotTestBed;
import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;


/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that FiringDock moves 
 * randomly more than 5 times each round.
 * 
 * @author Lyneth Peou
 *
 */
public class TestFiringDockMovement extends RobotTestBed {
  /** True if the robot moves to new position. */
  Boolean moves = false;
  /** Total of new position. */
  int totalMoves; 
  
  /** Initial position. */
  double initialX = 0.0;
  double initialY = 0.0;   

  /**
   * Specifies that Crazy and FiringDock are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,lnp.FiringDock";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  } 

  /**
   * Count the total of new position(X,Y) of the FiringDock after each turn.
   * 
   * @param e Details about the TurnEndedEvent.
   */  
  @Override
  public void onTurnEnded(TurnEndedEvent e) {
    IRobotSnapshot r = e.getTurnSnapshot().getRobots()[1];    
    
    if (initialX == 0.0 && initialY == 0.0) {
      initialX = r.getX();
      initialY = r.getY();
    }
    
    if (initialX != r.getX() || initialY != r.getY() ) {
      totalMoves++;
      initialX = r.getX();
      initialY = r.getY();      
    }   
  }
  
  /**
   * Asserts that FiringDock moves at least 5 times.
   * @param event Details about the completed battle.
   */
  public void onRoundEnded(RoundEndedEvent event) {
    // Check to make sure FiringDock moves more than 5 times.
    if (totalMoves > 5) {
      moves = true;
    }
    assertTrue("Check FiringDock movement", moves );   
  }  
  
}
